package com.rich.paas.controller.ba;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rich.paas.annotation.NoLogin;
import com.rich.paas.controller.BaseController;
import com.rich.paas.domain.Result;
import com.rich.paas.domain.param.CompanyLoginParam;
import com.rich.paas.entity.Company;
import com.rich.paas.service.CompanyService;
import com.rich.paas.util.Md5Util;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chenhao
 */
@RestController
@RequestMapping("/user")
@Api(value = "BA登录-API", description = "BA登录-API")
public class UserController extends BaseController {

    @Autowired
    private CompanyService companyService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ApiOperation(value = "帐号密码登录接口", notes = "帐号密码登录接口")
    @NoLogin
    public Result login(@RequestBody CompanyLoginParam companyLoginParam) {
        //todo
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("phone",companyLoginParam.getPhone());
        wrapper.eq("login_password",Md5Util.md5Encode(Md5Util.md5Encode(companyLoginParam.getLoginPassword())));
        Company company = companyService.selectOne(wrapper);
        if (company != null){
            baUserLoginSuccess(company.getId());
            return Result.success("登录成功");
        }

        return Result.failed("帐号密码错误");
    }


}
